package com.company.OfferGuide;

import java.util.LinkedList;
import java.util.Scanner;

public class 圆圈中最后剩下的数字 {

    public static void main(String[] args) {
        System.out.println(lastRemaining(5, 3));
    }

    public static int lastRemaining(int n, int m) {
        int last = 0;   //存活的最后一个人的位置
        for (int i = 2; i <= n; i++) {
            last = (last + m) % i;
        }
        return last;
    }

}
